<cfcomponent displayname="CrafterKeyMap" extends="crafter.CrafterDocument" output="no">

	
	<!--- getKeyValue() --->
	<cffunction name="getKeyValue" access="public" returntype="any" output="no">
		<cfargument name="key" type="string" required="yes" />
		<cfscript>
			local.sKeyToXpath = "//item[key='#arguments.key#']//value";
			local.arSearchResults = XmlSearch(getXml(),local.sKeyToXpath);
			if (ArrayLen(local.arSearchResults) GT 0) {
				return 	local.arSearchResults[1].XmlText;
			}
			else {
				return "";
			}
		</cfscript>
	</cffunction>
	
	
	<!--- getKeyValueAsTextObject() --->
	<cffunction name="getKeyValueAsTextObject" access="public" returntype="any" output="no">
		<cfargument name="sKey" type="string" required="yes" />
		<cfset var xPath = "//item[key='#Arguments.sKey#']//value" />
		<cfreturn getValueAsTextObject(xPath) />
	</cffunction>
	
	
	<!--- getKeys() --->
	<cffunction name="getKeys" access="public" returntype="array" output="no">
		<cfscript>
			local.xPath = "//item/key";
			local.arItems = XmlSearch(getXml(),local.xPath);
			local.arKeys = ArrayNew(1);
			ArrayResize(local.arKeys, ArrayLen(local.arItems));
			
			for (local.i=1;i LTE ArrayLen(local.arItems); local.i++) {
				local.arKeys[local.i] = local.arItems[local.i].XmlText;
			}
			
			return local.arKeys;
		</cfscript>
	</cffunction>
	
	
	<!--- getValuesAsStruct() --->
	<cffunction name="getValuesAsStruct" access="public" returntype="struct" output="no">
		<cfscript>
			local.arKeys = getKeys();
			local.stMapAsStruct = StructNew();
			for (local.i=1;i LTE ArrayLen(local.arKeys); local.i++) {
				local.stMapAsStruct["#local.arKeys[local.i]#"] = getKeyValue(local.arKeys[local.i]);
			}
			return local.stMapAsStruct;
		</cfscript>
	</cffunction>
	
</cfcomponent>